<?php

// +----------------------------------------------------------------------
// |ZBPHP[基于ThinkPHP5.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2019 http://www.benbenwangluo.com
// +----------------------------------------------------------------------
// | Author 似水星辰 [ 2630481389@qq.com ]
// +----------------------------------------------------------------------
// | 中犇软件 技术六部 出品
// +----------------------------------------------------------------------
namespace app\customer\validate;

use think\Validate;

/**
 * 店铺设置
 * @author 晓风<215628355@qq.com>
 * @date 2021-5-27 16:36:26
 */
class Shop extends Validate {

    //定义验证规则
    protected $rule = [
       'store_id|店铺ID' => ["integer","gt"=>0],
       'store_name|店铺名称' => ['require',"max"=>20],
       'store_logo|店铺LOGO' => ['require',"integer"],
       'greeting|问候语' => ["max"=>100,"min"=>10],     
       'service_date|营业时间' => ["max"=>11,"dateFormat"=>"H:i-H:i"],  
       'service_phone|客服电话' => ["max"=>20,"checkTel"],  
       "service_qq|QQ"=>["max"=>20,"regex"=>'/^[1-9]{1}[0-9\-]{4,10}$/'],
       "service_wechat|微信号"=>["max"=>20,"regex"=>'/^[a-zA-Z]{1}[-_a-zA-Z0-9]{5,19}$/'],
       "service_email|EMAIL"=>["max"=>50,"email"],
    ];
    //定义验证提示
    protected $message = [
        "service_qq.regex"=>"QQ号格式不正确",
        "service_wechat.regex"=>"微信号格式不正确",
        "store_name.unique"=>"店铺名称已存在",      
    ];
    //定义验证场景
    protected $scene = [
    ];
    
     /**
     * 通用电话验证器
     * @author 晓风<215628355@qq.com>
     * @param string $value 值
     * @param int $rule 规则
     * @param array $data 数据
     * @param string $filed 字段  
    */
    function checkTel($value,$rule="")
    {
        $regxArr = array(
          'mobile'  =>  '/^(\+?86-?)?(18|15|13)[0-9]{9}$/',
          'tel' =>  '/^(010|02\d{1}|0[3-9]\d{2})-\d{7,9}(-\d+)?$/',
          '400' =>  '/^400(-\d{3,4}){2}$/',
        );
        if($rule && isset($regxArr[$rule]))
        {
          return preg_match($regxArr[$rule], $value) ? true:false;
        }
        foreach($regxArr as $regx)
        {
          if(preg_match($regx, $value ))
          {
            return true;
          }
        }
        return false;
    }

}
